home *** CD-ROM | disk | FTP | other *** search
/ Space & Astronomy / Space and Astronomy (October 1993).iso / mac / TEXT / SPACEDIG / V09_5 / V9_527.TXT < prev    next >
Internet Message Format  |  1991-07-08  |  34KB

  1. Return-path: <ota+space.mail-errors@andrew.cmu.edu>
  2. X-Andrew-Authenticated-as: 7997;andrew.cmu.edu;Ted Anderson
  3. Received: from corsica.andrew.cmu.edu via trymail for +dist+/afs/andrew.cmu.edu/usr1/ota/space/space.dl@andrew.cmu.edu (->+dist+/afs/andrew.cmu.edu/usr1/ota/space/space.dl) (->ota+space.digests)
  4.           ID </afs/andrew.cmu.edu/usr1/ota/Mailbox/0Yf8kiy00UkVAQnE5m>;
  5.           Sat,  1 Jul 89 05:17:34 -0400 (EDT)
  6. Message-ID: <8Yf8kaK00UkVMQlU4r@andrew.cmu.edu>
  7. Reply-To: space+@Andrew.CMU.EDU
  8. From: space-request+@Andrew.CMU.EDU
  9. To: space+@Andrew.CMU.EDU
  10. Date: Sat,  1 Jul 89 05:17:26 -0400 (EDT)
  11. Subject: SPACE Digest V9 #527
  12.  
  13. SPACE Digest                                      Volume 9 : Issue 527
  14.  
  15. Today's Topics:
  16.            Re: Satellite Images - at home!
  17. ----------------------------------------------------------------------
  18.  
  19. Date: 28 Jun 89 20:34:19 GMT
  20. From: rochester!rit!cci632!ccicpg!paulm@cu-arpa.cs.cornell.edu  (tmp Paul Moreau usenet acct)
  21. Subject: Re: Satellite Images - at home!
  22.  
  23.  
  24. Here is the document, schematic, and code to receive pictures for an
  25. Atari ST
  26.  
  27.  
  28. -------------------------------------------------------------------------------
  29.  
  30.                 2400HZ Crystal phase lock Weather Satellite decoder
  31.                              By Mike Gore April 1988
  32. Part 1 of 3
  33.  
  34.  
  35.     This posting is broken into 3 parts.  Part 1 contains a functional 
  36. outline of the decoder, software overview and some information of interest 
  37. on the NOAA and Meteor weather satellites. Part 2 contains the decoder 
  38. diagram in ascii text format. Part 3 contains some functional test
  39. software written for the ATARI ST. 
  40.  
  41.  
  42.     The NOAA and Meteor weather satellites transmit images of the Earth
  43. using an APT format. This format is a 120 lines (Meteor) or 240 line (Noaa) 
  44. per minute encoded with a 2400HZ AM audio signal that is transmitted on a FM 
  45. modulated VHF downlink. Frequencies of interest are 137.5MHZ, 137.620MHZ for 
  46. NOAA and 137.300MHZ, 137.400MHZ and 137.850MHZ for the soviet Meteor satellites.
  47. The receiver bandwidth must be 30KHZ or more for good results. Basically
  48. the satellites scan the Earth a right angles to their orbit with a mirror that 
  49. is directed to a photo detector. The light reaching the detector alters the 
  50. 2400HZ  carrier amplitude which in turn affects the bandwidth or spread of
  51. of the FM downlink at a given moment. The NOAA craft transmit both visual
  52. and IR images where the Meteor crafts only send visual band images.
  53. Since my initial posting on this subject, about 1 month ago, I happened across 
  54. the 1987 ARRL handbook and found that it has some good references for this 
  55. subject along with a functional decoder. My decoder is a mix of several ideas 
  56. all in mixed into one with it's main feature being a rather rather novel 
  57. demodulator design.
  58.  
  59.  
  60. Circuit description:
  61.  
  62.     The demodulator uses a bandpass network built of 2 high and 2 low pass
  63. filters. The stop bands are currently 1200HZ and 3600HZ however this value
  64. was somewhat a matter of experiment on my part. The filter feeds a full wave
  65. active rectifier that can be balanced with a 10K variable resistor. The
  66. rectifier part is similar in form to that found in several National Linear 
  67. AP Notes yet I liked the version in the 1987 ARRL handbook enough that
  68. I used theirs. What follows the full wave rectifier is a resetable integrator
  69. followed by a sample hold. The analog switches are made by GE Intersel part
  70. number is DG201. The op amps are TL082 dual or TL084 quad op amps however you
  71. can use LF353's as well. I chose to use the resetable integrator rather
  72. then a low pass filter after the rectifier in order to try to push the 
  73. overall bandwidth of the system to the limit. The results are very good,
  74. the main advantage being that aliasing errors are virtually gone 
  75. because the integration period is synced with the 2400 AM carrier. The 
  76. integrator may be be run at half cycle intervals however the circuit
  77. described here is wired for 1 cycle samples. In order to phase lock
  78. the system clock with the 2400HZ AM carrier I chose a Crystal VXO design.
  79. Phase locking is not really required if one is willing to live with sample
  80. position aliasing. - This would normally be noticed in a feature in the image 
  81. that is at right angles to the scan path as a slow drift of one pixel as
  82. a function of the phase error of the sample. The Sample error would normally
  83. change as a function of doppler shift and or any drifting in the local system 
  84. clock without phase locking. I found that since NOAA scans at 240 lines per 
  85. minute with two images interleaved on alternate scans there isn't much 
  86. bandwidth left over such that one might be tempted to toss some away on sample 
  87. errors.  I should note that the Meteor satellites run their carrier slightly 
  88. off 2400HZ and my system can not phase lock on their carrier - in fact there 
  89. doesn't seem to be a strict 1 to 1 relationship between carrier frequency and
  90. scan rate as is the case with NOAA. The loss of lock still gives good
  91. images - they just are not the best possible. With NOAA the 2400HZ
  92. signal is 1 to 1 mapped to the scan rate so it is possible to
  93. use it rather then the 7 cycle 1200 HZ burst that is modulated on the
  94. 2400 HZ carrier to keep frame sync. Meteor use a 300 HZ 7 cycle burst.
  95. I chose not to use the 7 cycle sync markers in favor of a manual
  96. software offset adjustment in the display program. The programs
  97. are broken into two sections - data collection and data display.
  98. The VXO uses a standard XOR phase comparator for locking yet there is no loop 
  99. filter needed. It works out that the phase jitter is to small to even think 
  100. about with an 8bit A/D. Basically the XOR gate forces the 2400 divided
  101. reference clock to be roughly 90 degrees out of phase with the downlink
  102. 2400HZ carrier. The crystal I used is series tuned such that when the analog
  103. switch closes the frequency runs too low and when it is open it runs too high.
  104. The 20pf cap across the switch adds to the switch capacitance to give
  105. a minimal value to keep the oscillator stable. The idea is to weight the
  106. two values of frequency with the switch open and then closed such that
  107. it averages to 2457600 MHZ and with about +/- 150HZ swing. The swing
  108. must at least be in excess of the worst case doppler shift - the higher
  109. the value the faster the lock but with a chance of larger phase errors
  110. as a function of noise. This circuit works very well at locking on a
  111. signal almost hidden in noise much unlike what one would expect with
  112. a simple analog PLL. Of course a noisy signal is of no real value
  113. but even noise bursts can cause loss of sync with a normal non VXO analog PLL 
  114. design. 
  115.  
  116.     The software is very crude and was patched together from odd
  117. bit's of code I wrote for other things. It was hacked to test hardware
  118. that changed just about every day so little attempt was made to clean
  119. it up in however it is actually functional. My only intent for including
  120. it here in this form is for testing and feedback on the hardware. I plan
  121. to actually write a 'real' display/collection program rather soon.
  122. [ That will be of course just to show anyone with doubts that - yes I 
  123.   actually can program dispite my worst efforts here :-)! ]
  124.  
  125. Anyway, the test programs are 'documented' as follows:
  126.  
  127. The data collection program takes 1 argument which is simply the file name 
  128. to save the collected data with. The display program takes no arguments but 
  129. is command driven. The programs are run from the Mark Williams shell - I
  130. should mention that I used the MW C complier to write this code. The commands 
  131. are:
  132.  
  133. H min max
  134.     - Sets the values to be black and white where min and max are
  135.      number integer values bound by 0 and 255. The program will then 
  136.          attempt to expand the range of these values as a crude form of
  137.          contrast enhancement. This really should be histograms equalization
  138.      since all the data is at hand - but hey this is a hack program
  139.          remember ? :-)
  140.  
  141. D offset direction
  142.     - Sets the display offset and direction where offset is a value
  143.           between 0 and 1199 and direction is either 1 for north to
  144.           south passes or -1 for south to north passes.
  145. h
  146.     - Dumps a histogram of the in memory window selected by the D
  147.       command
  148. d
  149.     - displays the in memory window set by the D command and
  150.           some contrast maps and various stuff - Press return to exit 
  151.       this display
  152.  
  153. r file line-skip
  154.     - reads a file where line-skip is the number of scan lines
  155.       to skip into the file. Offset is remembered across reads.
  156.  
  157. w file
  158.     - writes a Dagas format file from the in memory copy
  159.  
  160. A file
  161.     - writes an old format AIM file
  162.  
  163. W file  - writes a raw 8 bit image file
  164.  
  165.  
  166. q    - quit
  167.  
  168. --
  169. The following are symbols used for the diagram in part 2 of 3
  170.  
  171.  
  172. Labels:
  173.         (round braces)
  174.  
  175. Traces:
  176.  
  177.      (Corner)    +----O  (Main signal I/O or control)
  178.                  |
  179.  (Connection)    o
  180.  
  181.  
  182. Resistor:
  183.         100 = 100 ohms
  184.         4K7 = 4700 ohms
  185.         v10K = 10000 ohms variable
  186.  
  187. Capacitor:
  188.         3n3 = 3.3 nanofarad
  189.  
  190. Diode:
  191.             -I<-             ->I-
  192.      (Cathode)(Anode)   (Anode)(Cathode)
  193.  
  194. FET:
  195.         o       (Drain)
  196.         D        
  197.       oG        (Gate)
  198.         S
  199.         o        (Source)
  200.  
  201. Inductor:
  202.  
  203.         --44mH--
  204.  
  205. Crystal:
  206.  
  207.         -Y-
  208.  
  209. Op Amp:
  210.  
  211.     (-In) o-
  212.            OPo (Out)
  213.     (+In) o+
  214.  
  215. Analog switch:
  216.  
  217.          (Control)
  218.  
  219.             O
  220.  (In/Out)  oXo   (In/Out)
  221.  
  222. NAND gate:
  223.     (IN 1)  o
  224.             NANDo  (OUT)
  225.     (IN 2)  o
  226.  
  227. XOR gate:
  228.     (IN 1)  o
  229.             XORo  (OUT)
  230.     (IN 2)  o
  231.  
  232.  
  233.  
  234.                 2400HZ Crystal phase lock Weather Satellite decoder
  235.                              By Mike Gore April 1988
  236. Part 2 of 3
  237.  
  238.  
  239.     See part 1 for a description of the the symbols used
  240.         in this diagram and a function outline.
  241.  
  242.  
  243. Analog section:
  244.  
  245.  
  246. Power in                
  247.  
  248. (+12)---100---o---------O (+12 to all OP amps)
  249.              +|
  250.              47uf
  251.               |
  252. (GND)---------o----o----O (AGND and DGND) - AGND is to be tied to DGND here
  253.              +|    |
  254.              47uf  |
  255.               |    |
  256. (-12)---100---o---------O (-12 to all OP amps)
  257.                    !
  258.                    |
  259.                   47uf
  260.                   +|
  261. (+5)---------------o----O (Logic +5)
  262.  
  263.  
  264.  
  265.                +----13K------+
  266.                |             |      +-----13K-----+
  267.   (IN)  O--3n3-o-3n3-o--o-   |      |             |
  268.                      |   OPo-o--13K-o-13K-o--o-   |
  269.                      |  o+   |            |   OPo-o---+
  270. (AGND)  O--+         |  |   27K           |  o+   |   |
  271.            |        13K |    |            |  |   27K  |
  272.            |         |  +----o           10n |    |   |
  273.            |         |       |            |  +----o   |
  274.            |         |      47K           |       |   |
  275.            |         |       |            |      47K  |
  276.            |         |       |            |       |   |
  277.      +-----o---------o-------o------------o-------o   |
  278.      |                                                |
  279.      |                                                |
  280.      |   +--------------------------------------------+
  281.      |   |
  282.      |   |     +-----13K-----+
  283.      |   |     |             |      +-----13K-----+
  284.      |   +-3n3-o-3n3-o--o-   |      |             |
  285.      |               |   OPo-o--13K-o-13K-o--o-   |
  286.      |               |  o+   |            |   OPo-o---+
  287.      |               |  |   27K           |  o+   |   |
  288.      |              13K |    |            |  |   27K  |
  289.      |               |  +----o           10n |    |   |
  290.      |               |       |            |  +----o   |
  291.      |               |      47K           |       |   |
  292.      |               |       |            |      47K  |
  293.      |               |       |            |       |   |
  294.      o---------------o-------o------------o-------o   |
  295.      |                                                |
  296.      |                                                |
  297.      |                                                |
  298.      |   +--------------------------------------------+
  299.      |   |
  300.      |   |
  301.      |   |             +-4K7-o-v10K-o-10K-+
  302.      |   |             |            |     |
  303.      |   |       +-10K-o-I<-+       |     | (IN1)
  304.      |   |       |          |       |     |
  305.      |   |       o-10K-o->I-o       o-    |   O
  306.      |   |       |     |    |        OPo--o--oXo----o
  307.      |   |       |     o----|-------o+              |
  308.      |   |       |     |    |                       |
  309.      |   +---10K-o-    |    |                       |
  310.      |            OPo--|----o-                      |
  311.      |           o+    |     OPo--1K-o----O (PHASE) |
  312.      |           |     |    o+       |              |
  313.      |          10K   10K   |   +->I-o->I-O (+5)    |
  314.      |           |     |    |   |                   |
  315.      o-----------o-----o----o---o                   |
  316.      |                                              |
  317.      |                                              |
  318.      |   -------------------------------------------+
  319.      |   |
  320.      |   |                    +-------+
  321.      |   |        (IN4) (IN3) |       |
  322.      |   |                    +-o-    |
  323.      |   |          O     O      OPo--o--4K7--O (VID)
  324.      |   |       +-oXo-o-oXo-o--o+
  325.      |   |       |     |     |              +-O (AGND)
  326.      |   |       o-3n3-o     |              |
  327.      |   |       |     |     |              |
  328.      | v10K--10K-o-    |    n15             |
  329.      |   |        OPo--o     |              |
  330.      |   |       o+          |              |
  331.      |   |       |           |              |
  332.      o---o-------o-----------o--------------+
  333.      |                       |
  334.      |                      10n
  335.      |                       |
  336.      |                       o---100---O (+12)
  337.      |                       D
  338.      |           +--o---o--oG  (MPF102)
  339.      |           |  |   |    S
  340.      |           |  |   |    o
  341.      | 2.4576MHZ Y  |   |    |
  342.      |           |  |  n15   |
  343.      |           |  |   |    |
  344.      |        +--o 220K |    |
  345.      |        |  |  |   o----o--n47--O (CLOCK)
  346.      |        o  |  |   |    |
  347.      | (IN2) OX 20p | 44mH  n15    +-O (AGND)
  348.      |        o  |  |   |    |     |
  349.      |        |  |  |   |    |     |
  350.      o--------o--o--o---o----o-----o
  351.  
  352.  
  353. Digital Section:
  354.  
  355.  
  356.  
  357. (+5) O-------------------o---------------o
  358.                          |               |
  359.               Mc14020    |    74ls164    |
  360.              =========   |   =========   |
  361.              I    VccI16-o--7IClr VccI14-o
  362.              I       I       I       I   |
  363.              I       I 9----8I>    QaI 3---------------1o
  364. (CLOCK) O--10I>      I       I     QbI 4-----12o        NANDo 3---O (IN3)
  365.              I       I       I       I   |     XORo11--2o
  366.              I       I14o-o-1IA      I   +---13o
  367.              I       I  | +-2IB      I   |
  368.              I       I  |    I     QcI 4---------------4o
  369.              I       I  |    I     QdI 5------9o        NANDo 6-o-O (IN4)
  370.              I       I  |    I       I   |     XORo 8--5o        |
  371.              I       I  |    I       I   +---10o                 |
  372.              I       I  |    I       I                           |
  373.          +-11IClr    I  |    I       I               +-----------+
  374.          o--8IGnd    I  | +-7IGnd    I               |
  375.          |   =========  | |  =========               o--9o
  376.          |              | |                          |   NANDo 8---O (IN1)
  377.          |              | |                          o-10o
  378.          |              | |
  379. (DGND)---o----------------o
  380.                         |
  381.                         |
  382.                         o------------O (A/D Clock)
  383.                         |
  384.                         +----2o
  385.                               XORo---O (IN2)
  386.                 (PHASE) O----1o
  387.  
  388. A/D Sect|on:
  389.  
  390.  
  391.  
  392.                     ADC0809
  393.                 ===============
  394.          +----12IVref+        I
  395.          |      I             I
  396.         100     I             I            DB25 Atar| pr|nter port
  397.          |      I             I             ... set to *|nput* mode 
  398. (+5)-----o----11IVcc        D0I17-----O  2
  399.          |     9IOE         D1I14-----O  3
  400.          |      I           D2I15-----O  4
  401. (IN1)-------o--6IStart      D3I 8-----O  5
  402.          |  +-22IAle        D4I18-----O  6
  403.          |      I           D5I19-----O  7
  404. (VID)---------26IIN0        D6I20-----O  8
  405.          |      I           D7I21-----O  9
  406.        + |      I             I
  407.        47uf     I             I
  408.          |      I          EOCI 7-----O 11
  409.          |      I             I
  410.          o----25IA            I    o--O 18
  411.          o----24IB            I    o--O 19
  412.          o----23IC            I    o--O 20
  413.          |      I             I    o--O 21
  414.          |      I             I    o--O 22
  415.          o----16IVref-        I    o--O 23
  416.          |      I             I    o--O 24
  417.          |      I             I    o--O 25
  418.          o----13IGND          I    |
  419.          |      I             I    |
  420.          |      ===============    |
  421.          |                         |
  422. (DGND) O-o-------------------------o
  423. (AGND)
  424.  
  425.  
  426.  
  427. This file includes three files: Makefile, get.c, disp.c
  428.  
  429. ----------------------------------- Makefile
  430. CFLAGS= -V
  431. OBJS=
  432.  
  433. disp:    disp.o $(OBJS)
  434.           cc $(CFLAGS) disp.o $(OBJS) -o disp.prg
  435.  
  436. disp.o:   disp.c
  437.           cc -c $(CFLAGS) disp.c
  438.  
  439. get:    get.o $(OBJS)
  440.           cc $(CFLAGS) get.o $(OBJS) setrte.s -o get.prg
  441.  
  442. get.o:   get.c
  443.           cc -c $(CFLAGS) get.c
  444.  
  445. ----------------------------------- get.c ---
  446.  
  447. #include "osbind.h"
  448.  
  449. #define EXT
  450.  
  451. #define VSIZE 2400
  452. #define HSIZE 1200
  453. #define VMEM (VSIZE*12)
  454.  
  455. #define setres(a)   ( *((char *) 0xff8260L) = (int) (a)) 
  456. #define getres()   ( *((char *) 0xff8260L) & 0xff)
  457. #define extsync()   ( *((char *) 0xff820aL) = (1) )
  458. #define intsync()   ( *((char *) 0xff820aL) = (0) )
  459. #define giport(a)   ( *((char *) 0xff8800L) = (a) )
  460. #define giwrite(a)  ( *((char *) 0xff8802L) = (a) )
  461. #define giread()    ( *((unsigned char *) 0xff8800L) )
  462. #define strobeon()  ( giport(14), giwrite(giread() | 0x20) )
  463. #define strobeoff() ( giport(14), giwrite(giread() & ~0x20) )
  464. #define stat()      ( *((char *) 0xfffa01L) )
  465. #define setcol(a,b) ( *((int *) (0xff8240L+((int)(a)<<1)) ) = (int) (b) )
  466.  
  467.  
  468. long save_ssp;
  469. unsigned char *mptr;
  470. unsigned int Vsum = 0;
  471. unsigned int Vsize = 0L;
  472. unsigned int Vhead = 0L;
  473. unsigned int Vtail = 0L;
  474. int Verror = 0;
  475. int Vcnt = 0;
  476.  
  477. unsigned char Vbuff[HSIZE+1];
  478.  
  479. void extstrobe()
  480. {
  481.      setrte();
  482.  
  483.      if(Vsize < VMEM) {
  484.                giport(15);
  485.                mptr[Vhead++] = giread();
  486.                if(Vhead >= VMEM)
  487.                     Vhead = 0;
  488.                Vsize++;
  489.      }
  490.      else {
  491.           Verror = 1;
  492.      }
  493.      *((char *) 0xfffa11L) &= ~0x01;
  494. }
  495.  
  496.  
  497.  
  498. void timetick()
  499. {
  500.      setrte();
  501.  
  502.       if(++Vcnt >= 2) {
  503.           if(Vsize < VMEM) {
  504.                     mptr[Vhead++] = Vsum>>1;
  505.                     if(Vhead >= VMEM)
  506.                          Vhead = 0;
  507.                     Vsize++;
  508.           }
  509.           else {
  510.                Verror = 1;
  511.           }
  512.          Vcnt = 0;
  513.            Vsum = 0;
  514.      }
  515.      giport(15);
  516.      Vsum += giread();
  517.      strobeoff();
  518.      strobeon();
  519.      *((char *) 0xfffa0fL) &= ~0x20;
  520. }
  521.  
  522.  
  523. main(argc,argv)
  524. int argc; char *argv[];
  525. {
  526.      register unsigned char *ptr1, *ptr2;
  527.      register int i;
  528.      long          *vecp = (long *) 0x100L;
  529.      long          oldvec = 0L;
  530.      unsigned int oldmask = 0;
  531.      
  532.      int fp;
  533.  
  534.      if(argc < 2) {
  535.           printf("Usage: vmain OUTfile\n");
  536.           exit(1);
  537.      }
  538.  
  539.      if((fp=creat(argv[1],1)) < 0) {
  540.           printf("Can't open: %s\n",argv[1]);
  541.           exit(1);
  542.      }
  543.  
  544.      init();
  545.  
  546.      save_ssp = Super(0L);
  547. #ifdef EXT
  548.      Jdisint(0);
  549.      oldvec = vecp[0];
  550.      vecp[0] = (long) extstrobe;
  551.      oldmask = *((char *) 0xfffa03L);
  552.      *((char *) 0xfffa03L) |= 0x01;
  553.      Jenabint(0);
  554. #else
  555.      Xbtimer(0,3,32,timetick);
  556. #endif
  557.      Super(save_ssp);
  558.      
  559.      while(Verror == 0) {
  560.           if(Cconis() != 0) {
  561.                Verror = 1;
  562.                break;
  563.           }
  564.           if(Vsize < VSIZE )
  565.                continue;
  566.           ptr1 = (unsigned char *) &mptr[Vtail];
  567.           ptr2 = (unsigned char *) &mptr[Vtail+HSIZE];
  568.           for(i=0;i<HSIZE; i++ )
  569.                Vbuff[i]= (*ptr1++ + *ptr2++)>>1;
  570.           Vsize -= VSIZE;
  571.           Vtail += VSIZE;
  572.           if(Vtail >= VMEM)     
  573.                Vtail = 0;
  574.           if(write(fp,Vbuff,(int)HSIZE) != (int)HSIZE ) {
  575.                printf("Write error: %s\n", argv[1]);
  576.                Verror = 1;
  577.                break;
  578.           }
  579.      }
  580.  
  581.      save_ssp = Super(0L);
  582. #ifdef EXT
  583.      Jdisint(0);
  584.      vecp[0] = oldvec;
  585.      oldmask = *((char *) 0xfffa03L) = oldmask;
  586. #else
  587.      Xbtimer(0,0,0,0L);
  588. #endif
  589.      Super(save_ssp);
  590.  
  591.      close(fp);
  592.      portout();
  593. }
  594.  
  595.  
  596. init()
  597. {
  598.      register int i;
  599.     
  600.      Vsize = 0;
  601.      Vhead = 0;
  602.      Vtail = 0;
  603.      Verror = 0;
  604.  
  605.      portin();
  606.  
  607.      mptr = (unsigned char *) Malloc((long)(VMEM)+1L);
  608.      if(mptr == 0L) {
  609.           printf("Malloc Failed\n");
  610.           exit(1);
  611.      }
  612.      for(i=0;i<VMEM;++i)
  613.           mptr[i] = 0;
  614. }
  615.  
  616. portin()
  617. {
  618.      save_ssp = Super(0L);
  619.  
  620.      strobeon();
  621.      giport(7);
  622.      giwrite( (giread() & 0x7f) );
  623.  
  624.      *((char *) 0xfffa0fL) &= ~0x20;
  625.  
  626.      Super(save_ssp);
  627.  
  628. }
  629.  
  630. portout()
  631. {
  632.      save_ssp = Super(0L);
  633.  
  634.      giport(7);
  635.      giwrite( (giread() | 0x80) );
  636.      strobeon();
  637.  
  638.      Super(save_ssp);    
  639. }
  640.  
  641. --------------------------------- disp.c --------------------------
  642.  
  643. #include "osbind.h"
  644.  
  645. #define VSCAN 1200L
  646.  
  647. #define DSIZE       ((long)(320L * 200L))
  648. #define BSIZE          ((long)(VSCAN*200L))
  649. #define offset(x,y) ( (long) ( ((long)(x)) + VSCAN * ((long)(y))) )
  650.  
  651. #define XOFF 0
  652. #define YOFF 0
  653. #define XMIN 0
  654. #define XMAX 299
  655. #define YMIN 0
  656. #define YMAX 179
  657.  
  658.  
  659. #define setres(a)   ( *((char *) 0xff8260L) = (int) (a)) 
  660. #define getres()     ( *((char *) 0xff8260L) & 0xff)
  661. #define extsync()   ( *((char *) 0xff820aL) = (1) )
  662. #define intsync()   ( *((char *) 0xff820aL) = (0) )
  663. #define giport(a)   ( *((char *) 0xff8800L) = (a) )
  664. #define giwrite(a)  ( *((char *) 0xff8802L) = (a) )
  665. #define giread()    ( *((unsigned char *) 0xff8800L) )
  666. #define strobeon()  ( giport(14), giwrite(giread() | 0x20) )
  667. #define strobeoff() ( giport(14), giwrite(giread() & ~0x20) )
  668. #define stat()      ( *((char *) 0xfffa01L) )
  669. #define setcol(a,b) ( *((int *) (0xff8240L+((int)(a)<<1)) ) = ((int)(b))&0x1ff )
  670. #define getcol(a)      ( *((int *) (0xff8240L+((int)(a)<<1)) )  & 0x1ff )
  671.  
  672. unsigned int disp[] = {
  673.       0x000,0x001,0x011,0x111,
  674.       0x112,0x222,0x223,0x333,
  675.       0x334,0x444,0x445,0x555,
  676.       0x556,0x666,0x667,0x777
  677. };
  678.  
  679. unsigned int Smap[] = {
  680.       0x000,0x001,0x011,0x111,
  681.       0x112,0x222,0x223,0x333,
  682.       0x334,0x444,0x445,0x555,
  683.       0x556,0x666,0x667,0x777
  684. };
  685. unsigned int  Res;
  686.  
  687. unsigned char *mptr;
  688. unsigned char *sptr;
  689.  
  690. long     Vskip = 0L;
  691. int          Voff = 0;
  692. int       Vdir = 1;
  693. int          Vline = 0;
  694.  
  695. long      Vbase = 0xf8000L;
  696.  
  697. unsigned int  Vmap[256];
  698.  
  699. long      Vsize = 0L;
  700. int       Vmax = 255;
  701. int       Vmin = 0;
  702.  
  703. long      hist[256];
  704.  
  705. unsigned char buff[VSCAN];
  706.  
  707. long save_ssp;
  708.  
  709. char line[128], path[128], temp[128];
  710.  
  711. main(argc,argv)
  712. int argc; char *argv[];
  713. {
  714.      register unsigned int x,y;
  715.      unsigned int i,c;
  716.  
  717.      int hmin, hmax, hoff;
  718.      int fp,z;
  719.  
  720.      mptr = (unsigned char *) Malloc(BSIZE+1L);
  721.      if(mptr == 0L) {
  722.           printf("Malloc Failed\n");
  723.           exit(1);
  724.      }
  725.      vclr(mptr,BSIZE);
  726.      sptr = (unsigned char *) Malloc(DSIZE+1L);
  727.      if(sptr == 0L) {
  728.           printf("Malloc Failed\n");
  729.           exit(1);
  730.      }
  731.      vclr(sptr,DSIZE);
  732.  
  733.      while(1) {
  734.           printf("\n>");
  735.           gets(line);
  736.           switch(*line) {
  737.                case 'r':     
  738.                     sscanf(line,"%s %s %d", temp, path, &Vline);
  739.                     vclr(mptr, BSIZE);
  740.                     if((fp=open(path,0)) < 0) {
  741.                          printf("Can't open: %s\n",path);
  742.                          break;
  743.                     }
  744.                     Vskip = VSCAN * (long) Vline;
  745.                     lseek(fp,Vskip,0); 
  746.                     for(y=0;y<180; y+=20) {
  747.                          if(read(fp,&mptr[offset(0L,y)],
  748.                               (int)VSCAN*20)<(int)VSCAN*20)
  749.                                    break;
  750.                     }
  751.                     close(fp);
  752.                     break;
  753.                case 'w' :
  754.                     sscanf(line,"%s %s", temp, path);
  755.                     fp = creat(path,0666);
  756.                     if(fp >= 0) {
  757.                          z = 0;
  758.                          if(write(fp,&z,2) != 2) {
  759.                               printf("Write error:%s\n", path);
  760.                               close(fp);
  761.                               break;
  762.                          }
  763.                          if(write(fp,disp,32) != 32) {
  764.                               printf("Write error:%s\n", path);
  765.                               close(fp);
  766.                               break;
  767.                          }
  768.                          if(write(fp,((char *) sptr), 0x4000) != 0x4000) {
  769.                               printf("Write error:%s\n", path);
  770.                               close(fp);
  771.                               break;
  772.                          }
  773.                          if(write(fp,((char *) sptr + 0x4000L), 0x4000) != 0x4000) {
  774.                               printf("Write error:%s\n", path);
  775.                               close(fp);
  776.                               break;
  777.                          }
  778.                          close(fp);
  779.                     }
  780.                     else {
  781.                          printf("Can't open:%s\n", path);
  782.                     }
  783.                     break;
  784.                case 'W' :
  785.                     sscanf(line,"%s %s", temp, path);
  786.                     fp = creat(path,0666);
  787.                     if(fp >= 0) {
  788.                          for(y=0;y<180;++y) {
  789.                               for(x=0;x<300;++x) {
  790.                                    if(Vdir<0) 
  791.                                         c = (mptr[offset(299-x,179-y)+Voff] & 0xff);
  792.                                    else
  793.                                         c = (mptr[offset(x,y)+Voff] & 0xff);
  794.                                    buff[x] = c;
  795.                               }
  796.                               if(write(fp,buff,300) != 300) {
  797.                                    printf("Write error:%s\n", path);
  798.                                    break;
  799.                               }
  800.                          }
  801.                          close(fp);
  802.                     }
  803.                     else {
  804.                          printf("Can't open:%s\n", path);
  805.                     }
  806.                     break;
  807.                case 'A' :
  808.                     sscanf(line,"%s %s", temp, path);
  809.                     fp = creat(path,0666);
  810.                     if(fp >= 0) {
  811.                          for(y=0;y<180;++y) {
  812.                               for(x=0;x<256;++x) {
  813.                                    if(Vdir<0) 
  814.                                         c = (mptr[offset(299-x,179-y)+Voff] & 0xff);
  815.                                    else
  816.                                         c = (mptr[offset(x,y)+Voff] & 0xff);
  817.                                    buff[x] = c;
  818.                               }
  819.                               if(write(fp,buff,256) != 256) {
  820.                                    printf("Write error:%s\n", path);
  821.                                    break;
  822.                               }
  823.                          }
  824.                          for(x=0;x<256;++x)
  825.                               buff[x] = 0;
  826.                          for(;y<256;++y) {
  827.                               if(write(fp,buff,256) != 256) {
  828.                                    printf("Write error:%s\n", path);
  829.                                    break;
  830.                               }
  831.                          }
  832.                          close(fp);
  833.                     }
  834.                     else {
  835.                          printf("Can't open:%s\n", path);
  836.                     }
  837.                     break;
  838.                case 'H':
  839.                     sscanf(line,"%s %d %d", temp, &hmin, &hmax);
  840.                     if((hmin >= 0 && hmin <=255) && 
  841.                          (hmax >=0 && hmax <=255) && (hmax > hmin) ) {
  842.                               Vmin = hmin;
  843.                               Vmax = hmax;
  844.                     }
  845.                     else {
  846.                          printf("Must be bound by 0..256 and Max > Min\n");
  847.                     }
  848.                     break;
  849.                case 'h':
  850.                     for(i=0;i<256;++i)
  851.                          hist[i] = 0L;
  852.                     for(y=0;y<180;++y) {
  853.                          for(x=0;x<300;++x) {
  854.                               c = mptr[offset(x,y)+Voff] & 0xff;
  855.                               if(c>0)
  856.                                    ++hist[c];
  857.                          }
  858.                     }
  859.                     printf("\n");
  860.                     for(i=0;i<256;++i) {
  861.                          if((i%12) == 0)
  862.                               printf("%3d: ",i);
  863.                          printf(" %5ld", hist[i]);
  864.                          if((i%12) == 11)
  865.                               printf("\n");
  866.                     }
  867.                     break;
  868.                case 'D':
  869.                     Voff = 0; 
  870.                     Vdir = 1;
  871.                     sscanf(line,"%s %d %d", temp, &Voff, &Vdir);
  872.                     break;
  873.                case '?':
  874.                     printf("off:%d, dir:%d, min:%d, max:%d\n", Voff,Vdir,Vmin,Vmax);
  875.                     break;     
  876.                case 'd':
  877.                     if((Vmin < 0 && Vmin > 255) || 
  878.                          (Vmax < 0 && Vmax > 255) || (Vmax <= Vmin) ) {
  879.                          printf("Max and Min out of bounds\n");
  880.                          break;
  881.                     }
  882.                     scrinit();
  883.                     for(i=0;i<256;++i)
  884.                          hist[i] = 0L;
  885.                     for(i=0;i<Vmin;++i)
  886.                          Vmap[i] = 0;
  887.                     for(i=Vmin;i<=Vmax;++i) {
  888.                          c = 1L + (14L * (i - Vmin)  ) / (Vmax - Vmin);
  889.                          if( c > 14)
  890.                               c = 14;
  891.                          Vmap[i] = c;
  892.                     }
  893.                     while(i<256)
  894.                          Vmap[i++] = 15;
  895.                     for(y=0;y<180;++y) {
  896.                          for(x=0;x<300;++x) {
  897.                               c = (mptr[offset(x,y)+Voff] & 0xff);
  898.                               if(c>0)
  899.                                    ++hist[c];
  900.                               if(Vdir<0) 
  901.                                    set(299-x,179-y,Vmap[c]);
  902.                               else
  903.                                    set(x,y,Vmap[c]);
  904.                          }
  905.                     }
  906.  
  907.                     Vsize = 0L;
  908.                     for(i=0;i<256;++i) {
  909.                          if(Vsize < hist[i])
  910.                               Vsize = hist[i];
  911.                     }
  912.                     for(x=0;x<256;x++) {
  913.                          hoff = (int)((hist[x]*10L)/Vsize);
  914.                          if(hoff < 0)
  915.                               hoff = 0;
  916.                          if(hoff > 9)
  917.                               hoff = 9;
  918.                          set(x,189-hoff,15);
  919.                          if((x % 10) == 0)
  920.                             set(x,190,15);
  921.                          for(y=191;y<195;++y)
  922.                             set(x,y,x >> 4);
  923.                          for(y=196;y<200;++y)
  924.                             set(x,y,Vmap[x]);
  925.                     }
  926.                     vcopy(sptr,(char *)Vbase,DSIZE);
  927.                     gets(temp);
  928.                     screxit();
  929.                     break;
  930.                case 'Q':
  931.                case 'q':
  932.                     Mfree(sptr);
  933.                     Mfree(mptr);
  934.                     exit(0);
  935.                default:
  936.                     printf("\n?\n");
  937.                     break;
  938.           }
  939.      }
  940. }
  941.  
  942.  
  943.  
  944. scrinit()
  945. {
  946.      gbase();
  947.      Cursconf(0,30);
  948.      getpal(Smap);
  949.      Res=gres();
  950.      sres(0);
  951.      setpal(disp);
  952.      vclr(Vbase, DSIZE>>1);
  953. }
  954.  
  955. screxit()
  956. {
  957.      sres(Res);
  958.      setpal(Smap);
  959.      Cursconf(1,30);
  960. }
  961.  
  962. vclr(ptr,size)
  963. unsigned char *ptr;
  964. long size;
  965. {
  966.      while(size--)
  967.           *ptr++ = 0;
  968. }
  969.  
  970. vcopy(dest, src, size)
  971. unsigned char *dest, *src;
  972. long size;
  973. {
  974.      while(size--)
  975.           *dest++ = *src++;
  976. }
  977.  
  978. set(x,y,color)
  979. register unsigned int x,y,color;
  980. {
  981.      register unsigned int *ptr;
  982.      register unsigned int mask;
  983.  
  984.      mask = ((unsigned) 0x8000) >> (x & 0xf);
  985.      ptr = (unsigned int *) (Vbase + (160 * y) + ((x & 0xfff0) >> 1) );
  986.      *ptr++ |= ((color & 1) ? mask : 0);
  987.      *ptr++ |= ((color & 2) ? mask : 0);
  988.      *ptr++ |= ((color & 4) ? mask : 0);
  989.      *ptr++ |= ((color & 8) ? mask : 0);
  990. }
  991.  
  992. unset(x,y)
  993. register unsigned int x,y;
  994. {
  995.      register unsigned int *ptr;
  996.      register unsigned int mask;
  997.  
  998.      mask = ~( ((unsigned) 0x8000) >> (x & 0xf)  );
  999.      ptr = (unsigned int *) (Vbase + (y * 160) + ((x & 0xfff0) >> 1) );
  1000.      *ptr++ &= mask;
  1001.      *ptr++ &= mask;
  1002.      *ptr++ &= mask;
  1003.      *ptr++ &= mask;
  1004. }
  1005.  
  1006.  
  1007. setpal(v)
  1008. unsigned int *v;
  1009. {
  1010.      int  i;
  1011.  
  1012.      save_ssp = Super(0L); 
  1013.      for(i=0;i<16;++i) {
  1014.        setcol(i,v[i]);
  1015.      }
  1016.      Super(save_ssp);
  1017. }
  1018.  
  1019. getpal(v)
  1020. unsigned int *v;
  1021. {
  1022.      int  i;
  1023.  
  1024.      save_ssp = Super(0L); 
  1025.      for(i=0;i<16;++i) {
  1026.        v[i] = getcol(i);
  1027.      }
  1028.      Super(save_ssp);
  1029. }
  1030.  
  1031. gres()
  1032. {
  1033.      int  x;
  1034.      
  1035.      save_ssp = Super(0L); 
  1036.      x = getres();
  1037.      Super(save_ssp);
  1038.      return(x);
  1039. }
  1040.  
  1041. gbase()
  1042. {
  1043.      save_ssp = Super(0L); 
  1044.      Vbase = *((long *) 0x44e);
  1045.      Super(save_ssp);
  1046. }
  1047.      
  1048.  
  1049. sres(a)
  1050. unsigned int a;
  1051. {
  1052.      save_ssp = Super(0L); 
  1053.      setres(a);
  1054.      Super(save_ssp);
  1055. }
  1056.  
  1057. ------
  1058.  
  1059.    .===========================================================.
  1060.    |  ####### ####### ###  C O M P U T E R  |   =----------=   |
  1061.    |  ###     ###     ###  C O N S O L E S  |  An STC Company  |
  1062.    |  ####### ####### ###   Incorporated    |   =----------=   |
  1063.    |-----------------------------------------------------------|
  1064.    |  UUCP:  ...ccicpg!dl2!paulm         (Paul L. Moreau)      |
  1065.    |    or   ...ccicpg!dl1!paulm    (Diagnostics Software Eng) |
  1066.    |    or   ...ccicpg!paulm           (Irvine, California)    |
  1067.    `==========================================================='
  1068.  
  1069. ------------------------------
  1070.  
  1071. End of SPACE Digest V9 #527
  1072. *******************
  1073.